package shiyan2;

public class Student {
	String stuName;
    int stuId;
    String sex;
    Course[] courses;
    Student() {
        courses = new Course[3];
    }
    Student(int stuId,String stuName,String sex) {
        this.stuId = stuId;
        this.stuName = stuName;
        this.sex = sex;
        courses = new Course[3];
    }
    String getStuName() {
        return stuName;
    }

    void setStuName(String stuName) {
        this.stuName = stuName;
    }
    int getStuId() {
        return stuId;
    }
    void setStuId(int stuId) {
        this.stuId = stuId;
    }
    String getSex() {
		return sex;
	}
	void setSex(String sex) {
		this.sex = sex;
	}
    boolean Selected(Course course){
        boolean cnt=false;
        for(Course c:courses){
            if(c==course){
                cnt=true;
                break;
            }
        }
        return cnt;
    }
    boolean Null(Course course){
        boolean cnt=false;
        for(Course c:courses){
            if(c==null){
                cnt=true;
                break;
            }
        } 
        return cnt;
    }
    
    boolean addCourse(Course course){
        boolean cnt=false;
        if(!Selected(course)&&Null(course)){
            for(int i=0;i<this.courses.length;i++){
                if(courses[i]==null){
                    courses[i]=course;
                    course.addStudent(this);     
                    cnt=true;
                    break;
                }
            }
        }
        return cnt;
    }
    
    boolean removeCourse(Course course){
        boolean cnt=false;
        if(Selected(course)){
            for(int i=0;i<this.courses.length;i++){
                if(courses[i]==course){
                    courses[i]=null;
                    course.removeStudent(this); 
                    cnt=true;
                    break;
                }
            }
        }
        return cnt;
    }
    
    void displayCourse(){
        System.out.println(this.stuName+"  "+this.stuId+"  "+this.sex+"  ");
        for(Course c:courses){
            if(c!=null){
                System.out.print("课程编号："+c.getId()+"\n所选课程："+c.getName()+"\n上课地点："+c.getDestination()+"\n上课时间："+c.getTime()+"\n");
            }
        }
        System.out.println();
    }
}